package cate.game.serve;

import cate.game.GameBody;
import cate.game.framework.ModuleMan;
import cate.game.role.Role;
import cate.game.role.RoleRecordWriter;
import cp.solution.business.stat.role.RoleRecordEntity;
import cp.solution.rpc.RpcMsgHead;
import cp.solution.rpc.path.RpcSharePath;

/** 对外服务 */
public class ServeManager extends ModuleMan {

    @Override
    public void initIndependent(GameBody game) throws Exception {
        super.initIndependent(game);
    }

    @Override
    public void initDependent() throws Exception {
        game.rpcRecv().onRequestResponseTemplate(RpcSharePath.ROLE_RECORD_QUERY_2G, String.class, this::queryRoleRecordHandler);
    }

    private Object queryRoleRecordHandler(RpcMsgHead head, String roleId) {
        return this.queryRoleRecord(roleId);
    }

    public RoleRecordEntity queryRoleRecord(String roleId) {
        Role role = game.role.getRole(roleId, true);
        if(role == null) {
            return null;
        }
        return RoleRecordWriter.create(role);
    }

}
